;
$(function() {
	// 新建资金
	$('body').on('click', '.table-edit-btn.new', function(event) {
		var $this = $(this);
		// boolean payOut, MoneyType type, String contractId, String source,
		// Model model
		var payOut = $this.hasClass('payout');
		var type = $this.data('type');
		var contractId = $this.data('contract-id');
		var source = $this.data('source');

		$.suredy.showModal({
			icon : 'icon-upload',
			title : '新建资金信息',
			showFoot : false,
			uri : $.suredy.contextPath + '/money/new-form',
			data : {
				payOut : payOut,
				type : type,
				contractId : contractId,
				source : source
			}
		});
	});

	// 回收、退回资金
	$('body').on('click', '.table-edit-btn.change', function(event) {
		var $this = $(this);
		var moneyId = $this.data('money-id');

		$.ajax({
			url : $.suredy.contextPath + '/money/back',
			data : {
				moneyId : moneyId
			},
			type : 'post',
			dataType : 'json',
			success : function(result, textStatus, jqXHR) {
				if (!result || !result.success) {
					alert(result.msg || '操作失败！');
					return false;
				}

				refresh();
			},
			error : function(jqXHR, textStatus, errorThrown) {
				alert('操作失败！\n\n' + errorThrown);
			}

		});
	});

	// 删除资金
	$('body').on('click', '.table-edit-btn.delete', function(event) {
		var $this = $(this);
		var moneyId = $this.data('money-id');

		$.ajax({
			url : $.suredy.contextPath + '/money/delete',
			data : {
				moneyId : moneyId
			},
			type : 'post',
			dataType : 'json',
			success : function(result, textStatus, jqXHR) {
				if (!result || !result.success) {
					alert(result.msg || '操作失败！');
					return false;
				}

				refresh();
			},
			error : function(jqXHR, textStatus, errorThrown) {
				alert('操作失败！\n\n' + errorThrown);
			}

		});
	});

});